//
//  NSString+PYChineseToPinyin.m
//  catuncel
//
//  Created by Jim on 2017/10/24.
//  Copyright © 2017年 Jim. All rights reserved.
//

#import "NSString+PYChineseToPinyin.h"

@implementation NSString (PYChineseToPinyin)

- (NSString *)chineseToPinyin
{
    NSMutableString *pinyin = [self mutableCopy];
    
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
    
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
    
    NSArray *array = [pinyin componentsSeparatedByString:@" "];
    
    NSMutableString *string = [NSMutableString string];
    
    for (NSString *str in array) {
        
        [string appendString:str];
    }
        
    return string;
}

@end
